resource "alicloud_ram_user" "main" {
  name         = var.name
  display_name = "prom"
  mobile       = "86-18688888888"
  email        = "hello.uuu@aaa.com"
  comments     = "yoyoyo"
  force        = true
}

locals {
  policies = ["AliyunOSSFullAccess", "AliyunSTSAssumeRoleAccess", "AliyunLogFullAccess", "AliyunFCFullAccess", "AliyunDysmsFullAccess"]
}

resource "alicloud_ram_user_policy_attachment" "main" {
  count = length(local.policies) > 0 ? length(local.policies) : 0
  policy_name = element(local.policies, count.index)
  policy_type = "System"
  user_name   = alicloud_ram_user.main.name

  depends_on = [alicloud_ram_user.main]
}

resource "alicloud_ram_access_key" "main" {
  user_name   = alicloud_ram_user.main.name
  secret_file = "${path.module}/ak.json"

  depends_on = [alicloud_ram_user.main]
}

locals {
  ak = jsondecode(file("${path.module}/ak.json"))
}